// IO 函子的问题，没办法将一个返回封装值的函数运用到一个封装的值上
const fs = require('fs')
const fp = require('lodash/fp')

class IO {
  static of(value){
    return new IO(function(){
      return value
    })
  }
  constructor(fn){
    this._value=fn
  }
  map (fn){
    return new IO(fp.flowRight(fn,this._value))
  }
}

let readFile = function (filename) {
  return new IO(function () {
    return fs.readFileSync(filename, 'utf-8')
  })
}
let print = function (x) {
  return new IO(function () {
    console.log(x)
    return x
  })
}
let cat = fp.flowRight(print, readFile)
// IO(IO(x))
let r = cat('../lagou_study/fed-e-task-01-01/code/package-lock.json')._value()._value()
console.log(r)